package net.lab1024.sa.admin.module.business.yct.yctTeeth.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.dao.UsermembersDao;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.entity.UsermembersEntity;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.form.UsermembersAddForm;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.form.UsermembersQueryForm;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.form.UsermembersUpdateForm;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.vo.UsermembersVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户 Service
 *
 * @Author zhangben
 * @Date 2024-12-18 09:52:35
 * @Copyright 20241218
 */

@Service
public class UsermembersService {

    @Resource
    private UsermembersDao usermembersDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<UsermembersVO> queryPage(UsermembersQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<UsermembersVO> list = usermembersDao.queryPage(page, queryForm);
        PageResult<UsermembersVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(UsermembersAddForm addForm) {
        UsermembersEntity usermembersEntity = SmartBeanUtil.copy(addForm, UsermembersEntity.class);
        usermembersDao.insert(usermembersEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     * @param updateForm
     * @return
     */
    public ResponseDTO<String> update(UsermembersUpdateForm updateForm) {
        UsermembersEntity usermembersEntity = SmartBeanUtil.copy(updateForm, UsermembersEntity.class);
        usermembersDao.updateById(usermembersEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    public ResponseDTO<String> batchDelete(List<Integer> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        usermembersDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Integer membersId) {
        if (null == membersId){
            return ResponseDTO.ok();
        }

        usermembersDao.deleteById(membersId);
        return ResponseDTO.ok();
    }
}
